<?php

function http_post($url, $data,$hasCookie=false)
{
    $header = array(
        "User-Agent" => "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36",
        "Accept-Encoding" => "gzip, deflate, br",
        "Accept" => "*/*",
        "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8",
        "Connection" => "keep-alive"
    );
    $str = '';
    foreach ($data as $key => $val) {
        $str .= '&' . $key . '=' . $val;
    }
    $str = substr($str, 1);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    if (is_array($header) && !empty($header)) {
        $set_head = array();
        foreach ($header as $k => $v) {
            $set_head[] = "$k:$v";
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, $set_head);
    }
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);// 1s to timeout.
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    if($hasCookie){
        //    curl_setopt($ch, CURLOPT_COOKIE, '.AspNetCore.Identity.Application=CfDJ8HWGHCGoG4VOukkx1MN9RmV0dnazIjAmlREzECjM4drkb6yQ8lF_dsYdMQAiV4JYnRtJNWUmYSVf_alP2BxKpazS90HkyacaYXyCuYVMNH2_n7qmwR4umgZZhnA96Y0i6dHWiYGWtAMCvJ6a93gB8mWNYCx0Ho2PlyF6hjmMsY7_33Xal_0Wwi_CDvu2urmKFHhlT5D_PlYWHJAlIZ24TvPkzZlmbIHMV6xPvlJzZQr_4Z20SMlrnf6EwroqgZTZmy3xIzS_QSvMawJuydEfh-f-2mXmaGCGpd87H7aG7bY8hyELzYBrrX0s9qqf_vV3qS_MnYZdulvaX09DUr1QSEFH867fh2yFm_At5X_-s18bQ_j_jsRy2ugHUsSrEs8fFFHJlL6rt898U-QPf4arJhp-FeS6eXa8UjG6fPj8OMbWyXPpjCmqOww_AdYSjs3lmsvIi_C0bNGd2AKrh23Z7R5lh2jcbpfpuRFXYUAudPAQSxiM851MEYNoiLne0Qtj0O6PKG3Fa1mSn9d8HOAVywpu3i6g_H-ICsXHrsW56F-Ff5UBugMYL5V-QMIS_er_J5a6A3CYnUkvdJcINckbfAVPcjehgJiTeAWBpVrixgyserMYBy1tP5uCvH1tLwoAug7FAztn5TwXQKcqelVcCMc');
        curl_setopt($ch, CURLOPT_COOKIE, '.AspNetCore.Identity.Application=CfDJ8HWGHCGoG4VOukkx1MN9RmWAvJx0Z8mN6_LrVqa4ST7M0jOAit3TtPOG5CxGFio1WfgRN32zCciUxF6OaLaQdNcFOjFTGBVNYlZo2pA1tF-S8BkEKsBdqSFtZHOQHtdYmF6W8FcivAiCBRpeIM9K8y6nHmkncHpod9axLD87pdUbNG8GDNKfEdwl49o0ZfHLR3G2Jd1QxNs16dJNW1v_uuwRf8VBW8cchois3zTiHswVrvLbYTTLjXZI1a1H986Af_CWYAu9UnHMGwC8zDQgvFMC7ZLsATpuELbZpR5bgIFfxIM7S8fFoKe5HdtjzodKQgxLOvnlobQaAHBDiJqkHLjAmH7Ctz2mW2BQfv5pQalwdgVA_OXVGDFxd-p0tuDO4TanIPFQfAcspzOTyhwQP1CeLPf6G6CGr_vBqqQY1W0PBnitT0qvKxNpQwySqqfA1lNMzZy77-D1gPcuOvrLcO4Gmy30EA5xxxhGluAYiX9MTt6KUndH-244XCRga3q0l2qK0cpyH82gmAK8RDvS-cY2kW7rbGoljcQWUAXdphF4UTXFDDADAyH62AKS7-OJJuJCryHDEQ1S0oMXiGF7JEfOdyUMjIHofLbvXQw0GSxrr3Az4YWNIqRoGlQZwRli9w');
    }
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        return curl_error($ch);
    }
    curl_close($ch);
    return $response;
}

function http_get($url)
{
    $ch = curl_init();
    $header = array(
        "User-Agent" => "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36",
        "Accept-Encoding" => "gzip, deflate, br",
        "Accept" => "*/*",
        "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8",
        "Connection" => "keep-alive"
    );
    if (is_array($header) && !empty($header)) {
        $set_head = array();
        foreach ($header as $k => $v) {
            $set_head[] = "$k:$v";
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, $set_head);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 跟随重定向  
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // 最大重定向次数  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 
    $content = curl_exec($ch);
    if (curl_errno($ch)) {
        return "";
    }
    curl_close($ch);
    return $content;
}
